package svc

import (
	"mail/service/account/rpc/accountclient"
	"mail/service/property/rpc/propertyclient"
	"mail/service/receipt/model"
	"mail/service/receipt/rpc/internal/config"

	"github.com/zeromicro/go-zero/core/stores/sqlx"
	"github.com/zeromicro/go-zero/zrpc"
)

type ServiceContext struct {
	Config       config.Config
	ReceiptModel model.ReceiptModel

	AccountRpc  accountclient.Account
	PropertyRpc propertyclient.Property
}

func NewServiceContext(c config.Config) *ServiceContext {
	return &ServiceContext{
		Config:       c,
		ReceiptModel: model.NewReceiptModel(sqlx.NewMysql(c.Mysql.DataSource), c.CacheRedis),
		AccountRpc:   accountclient.NewAccount(zrpc.MustNewClient(c.AccountRpc)),
		PropertyRpc:  propertyclient.NewProperty(zrpc.MustNewClient(c.PropertyRpc)),
	}
}
